import matplotlib.pyplot as plt
import pandas as pd

# 读取CSV文件，第一行作为列名
df = pd.read_csv('sensitivity_table-副本.csv', header=0)

# 选择1列和2列作为x和y轴的自变量
x = df['Unit CLAP/day\n[$]']
y = df['Unit PLAC/day\n[$]']
z_label = ["Aver. TAC of \nbase schedule",
           "Reduced TAC [$]",
           "Sum of \nsuggested \npostponement\n [day]",
           "Ratio of \nunit CLAP \nto unit\n PLAC"
           ]
# 选择2、21、25、26列作为因变量
z1 = df.iloc[:, 2]  # 第2列:"Aver. TAC of base schedule [$]"
z2 = df.iloc[:, 21]  # 第21列:Reduced TAC[$]
z3 = df.iloc[:, 25]  # 第25列:Sum of suggested postponement [day]
z4 = df.iloc[:, 26]  # 第26列:Ratio of unit CLAP to unit PLAC

z = [z1, z2, z3, z4]

# 设置图形的大小
plt.figure(figsize=(15, 5))
# 3*3 subplot shares x and y axis
fig, axs = plt.subplots(3, 4, sharex=False, sharey=False)
plt.xticks(y[0:3])

for i in range(3):
    for j in range(4):
        axs[i, j].set_title("Unit CLAP=" + str(df.iloc[i * 3, 0]))
        axs[i, j].tick_params(axis='x', rotation=45)
        axs[i, j].set_ylabel(z_label[j])
        axs[i, j].set_xticks(y[i * 3: i * 3 + 3])
        yticks = z[j][i * 3: i * 3 + 3]
        axs[i, j].set_yticks(yticks)
        sub_x = y[i * 3: i * 3 + 3]
        sub_y = z[j][i * 3: i * 3 + 3]
        axs[i, j].plot(sub_x, sub_y, marker='o', linestyle='-',
                       color='red')  # 绘制 y 和 z 的关系)

# 调整子图间距
plt.tight_layout()

# 设置X轴和Y轴的全局标签:0.5表示水平居中，0.0表示在最下方
fig.text(0.5, 0.0, 'Unit PLAC/day [$]', ha='center')
# fig.text(0.04, 0.5, 'Values [$]', va='center', rotation='vertical')

# 调整子图间距
plt.tight_layout(rect=[0, 0.03, 1, 0.95])
# 显示图形
plt.show()
